<?php

 class BusinessAction extends CommonAction{
 	
 	 private  $table_name;
   	 function __construct(){
   	 	
   	 	$this->table_name = "Company";
   	 	parent::__construct();
   	 }
	

  	function  index(){
      
					import('ORG.Util.Page');

					 $count=M($this->table_name)->where("category >0")->count();// 查询总数据记录

					 $Page = new Page($count,C('PAGESIZE'));

					 $show= $Page->show();

	                    $temp = M($this->table_name)->where("category >0")->order("status ASC")->limit($Page->firstRow.','.$Page->listRows)->select();
                        foreach ($temp as $v){
                        	  $v['username'] = M('User')->where("uid=".$v['uid'])->getField('username');
                        	  $list[] =$v;
                        	
                        }
              	                   
	                      $this->assign("list",$list);

						  $this->assign("page",$show);

                          $this->display();

       }

       function check(){
       		
       	
       }
       
       /*
        * 状态审核
        */
       
       function shenhe(){
       		$id = empty($_GET['id'])?exit():$_GET['id'];
       		//$status=empty($_GET['status'])?exit():$_GET['status'];
       		$status=M('Company')->where('id='.$id)->getField('status');
       		if($status == 0){
       			M('Company')->where('id='.$id)->setField('status','1');
       			 $this->success('审核通过...',U('Business/index'));       			
       		}else{
       			M('Company')->where('id='.$id)->setField('status','0');
       			 $this->success('未通过',U('Business/index')); 
       		}
       	
       }
       
       
       
      function notice(){
      	
      	$id= htmlspecialchars($_GET['id']);
	              if(is_numeric($id)){
	              	 if(isset($_POST['submit'])){
	              	   	 	if(M('Company')->where('id='.$id)->setField('notice',$_POST['notice'])){
				       	 		  $this->success("更新成功！",U('index'));
				       	 		
				       	 	}else{
				       	 		 $this->error("更新失败！",U('index'));
				       	 	}
	              	 }else{
	              	 	$li=M('Company')->where('id='.$id)->find();
	              	 	$this->assign('li',$li);
	              	 	$this->display();
	              	 }      	
	    
	        }
      	
      	

       		
       	/*
       	      
       	      
       	      $this->success("更新成功！",U('index'));
       	      
       	      
       	      
       	$id = empty($_GET['id'])?exit():$_GET['id'];
       	
       		$li=M('Company')->where('id='.$id)->getField('notice');
       		
       		dump($li);
       	 */
       /*	if(isset($_POST['tijiao'])){
       		dump($_POST);
       		
       		
       	 	$data=$_POST['notice'];
       	 	if(M('Company')->where('id='.$id)->setField('notice',$data)){
       	 		 $this->success('通知更新成功...'); 
       	 		
       	 	}else{
       	 		 $this->error('通知更新成功...'); 
       	 	}
       	 	
       	 	
       	 }else{
       	 
       	 	 	$this->display();
       	 }*/
       
       }
       
       
       function add(){
  	  	
   	  	if(isset($_POST['submit'])){
   	  	     $data = $_POST;
           $data['createtime']=mktime();
           $data['status']= 1 ;
           $username = $_POST['username'];
           $password = md5($_POST['password']);
           $uid = M('User')->add(array('username'=>$username,'password'=>$password,'logintime'=>mktime(),'usertype'=>1,'status'=>1,'nickname'=>$_POST['title']));
           if(isset($uid)){
              	  $data['uid'] = $uid;	
              	     
           	      if(M($this->table_name)->add($data)){
		   	  	    	$this->success("操作成功！",U('index'));
		   	  	    }else{
		   	  	    	
		   	  	    	$this->error("操作失败");
		   	  	    }
           	
           } 

   	  	}else{
   	  		$this->list =M("Category")->select();
   	  		$this->display();
   	  	}
       	
       }

  	   /**

  	    * 

  	    * 编辑文章

  	    */

    	function  edit(){
	              $id= htmlspecialchars($_GET['id']);
	              if(is_numeric($id)){
	              	  if(isset($_POST['submit'])){
	              	  	  $data = $_POST;
	              	  	  $data['createtime']=mktime();
	              	  	  M($this->table_name)->where("id=".$id)->save($data);
	              	  	  $this->success("更新成功！",U('index'));
	              	  }else{
	              	  	$this->list =M("Category")->select();
	              	  	$this->li =M($this->table_name)->where("id=".$id)->find();
	              	  	$this->display();
	              	  }
	              	
	              }
  	 }

  	 function del(){

	        $qstr = $_GET['qstr'];
  		  	$data=M($this->table_name);  		  
			if(isset($qstr)){
			   $arr=explode(",",$qstr);

			   foreach($arr as $val){

			     $data->where("id=$val")->delete();
			       
			   }
			   $this->success("删除成功！",U('index'));			

			}else{

			  if(isset($_GET['id'])){

			  $data->where("id=".$_GET['id'])->delete();

			   $this->success("删除成功！",U('index'));

			  }else{

			  

			   $this->error("请选择要删除的ID");

			  }

			}

  	 }
  	 
 }
?>